package com.ytktt.study.week11.task11.service.impl;

import com.ytktt.study.week11.task11.entity.User;
import com.ytktt.study.week11.task11.mapper.UserMapper;
import com.ytktt.study.week11.task11.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @author ytk
 */
@RequiredArgsConstructor
@Service
@CacheConfig(cacheNames = "users")
public class UserServiceImpl implements UserService {

    private final UserMapper userMapper;

    // 开启spring cache
    @Override
    @Cacheable(key="#id",value="userCache")
    public User find(int id) {
        System.out.println(" ==> find " + id);
        return userMapper.find(id);
    }

    // 开启spring cache
    @Override
    @Cacheable //(key="methodName",value="userCache")
    public List<User> list(){
        return userMapper.list();
    }
}
